package _2022.hot100._621_任务调度器;


/**
 * @author： YHSimon
 * @date： 2022-06-16 10:35
 */
public class Solution {
    // 2ms
    public int leastInterval(char[] tasks, int n) {
        int[] tmp=new int[26];
        int countMaxTask=0;
        int maxTask=0;
        for(char c:tasks){
            tmp[c-'A']++;
            maxTask=Math.max(maxTask,tmp[c-'A']);
        }
        for (int i = 0; i < 26; i++) {
            if(tmp[i]==maxTask){
                countMaxTask++;
            }
        }
        return Math.max(tasks.length, (maxTask-1)*(n+1)+countMaxTask);
    }



    public static void main(String[] args) {
        // System.out.println((int)'Z');
        Solution s = new Solution();
        // System.out.println(s.leastInterval(new char[]{'A','A','A','B','B','B'}, 2));
        // System.out.println(s.leastInterval(new char[]{'A','A','A','A','A','A','B','C','D','E','F','G'}, 2));
        System.out.println(s.leastInterval(new char[]{'A','A','A','B','B','B','C','C','C','D','D','E'}, 2));

    }
}
